<template>
	<view class="public-view" :style="navType === 'voideIndex'?'background-color:#333;':''">
		<nav-bar v-if="showNavBar" :showLeft="showLeft" :backType="backType" :navRight="navRight" :navColor="navColor" :showAllClassBtn="allClassBtn" :showAddCard="showAddCard" :showIndex="navShowIndex" :navType="navType" :title="navTitle" @downQrCode="downQrCode"></nav-bar>
		<image class="top-bg-color" v-if="topBgShow === '1'" src="@/static/images/topBgimg.svg"></image>
		<image class="top-bg-color" v-if="topBgShow === '2'" src="@/static/images/topBgimg2.svg"></image>
		<image class="shop-bg-img" v-if="topBgShow === '3'" src="@/static/shop-bg-img.svg" mode="widthFix"></image>
		<image class="top-bg-color" v-if="topBgShow === '4'" style="top: -38rpx;" src="@/static/images/topBgimg3.svg"></image>
		<image class="top-bg-color" v-if="topBgShow === '5'" style="top: -38rpx;" src="@/static/images/live/my-live-bg-img.svg" mode="aspectFill"></image>
		<image class="top-bg-color" v-if="topBgShow === '6'" style="top: -38rpx;" src="@/static/images/vip/bg.png" mode="aspectFill"></image>
		<view class="" style="position: relative;z-index: 2;">
			<slot></slot>
		</view>
		<view style="position: relative;z-index: 300;">
			<slot name="popup"></slot>
		</view>
		
		<tabbar v-if="isTabbar" :tabbarType="tabbarType"></tabbar>
	</view>
</template>

<script>
	const compareVersion = function(version1, version2) {
	  const v1 = version1.split('.');
	  const v2 = version2.split('.');
	
	  for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
	    const num1 = parseInt(v1[i] || 0);
	    const num2 = parseInt(v2[i] || 0);
	
	    if (num1 > num2) {
	      return 1;
	    } else if (num1 < num2) {
	      return -1;
	    }
	  }
	
	  return 0;
	}
	const compareVersionCode = function(versionCode1, versionCode2) {
	  const v1 = versionCode1.toString();
	  const v2 = versionCode2.toString();
	
	  if (v1 === v2) {
	    return 0;
	  }
	
	  const parts1 = v1.split('.');
	  const parts2 = v2.split('.');
	
	  for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
	    const num1 = parseInt(parts1[i] || 0);
	    const num2 = parseInt(parts2[i] || 0);
	
	    if (num1 > num2) {
	      return 1;
	    } else if (num1 < num2) {
	      return -1;
	    }
	  }
	
	  return 0;
	}
	import tabbar from "@/components/tabbar/index.vue"
	import navBar from "@/components/navbar/index.vue"
	import config from "@/utils/config.js"
	import {setCid} from "@/utils/pagePublic.js"
	import {goTo} from "@/nav.js"
	export default {
		components:{
			"nav-bar":navBar,
			tabbar
		},
		props:{
			backType:{
				type:String,
				default:"black"
			},
			showLeft:{
				type:Boolean,
				default(){
					return true
				}
			},
			navColor:{
				type:String,
				default:"#333333"
			},
			showAddCard:{
				type:Boolean,
				default(){
					return false
				}
			},
			navTitle:{
				type:String,
				default:""
			},
			tabbarType:{
				type:String,
				default:"1"
			},
			topBgShow:{
				type:String,
				default(){
					return '1'
				}
			},
			navType:{
				type:String,
				default(){
					return "index"
				}
			},
			showNavBar:{
				type:Boolean,
				default(){
					return true
				}
			},
			isTabbar:{
				type:Boolean,
				default(){
					return false
				}
			},
			navShowIndex:{
				type:Boolean,
				default(){
					return false
				}
			},
			allClassBtn:{
				type:Boolean,
				default(){
					return true
				}
			},
			navRight:{
				type:Boolean,
				default(){
					return true
				}
			}
		},
		data() {
			return {
				
			}
		},
		created() {
			// #ifdef APP-PLUS
			setCid()
			let that = this
			this.$nextTick(()=>{
				this.$uploadApp((res)=>{
					if(compareVersion(config.version_name,res.data.version.version_name) === -1||compareVersionCode(config.version_code, res.data.version.version_code) === -1){
						if(that.$store.state.isupload !==2){
							if(that.$store.state.open_upload === 0){
								that.$store.commit("changeOpenUpload",1)
								uni.showModal({
									title:"温馨提示",
									content:"发现新版本!",
									showCancel:res.data.version.enforce !== 1?true:false,
									success(ares) {
										if(ares.cancel){
											that.$store.commit("changeUpLoad",2)
										}
										if(ares.confirm){
											that.$store.commit("changeOpenUpload",0)
											if(res.data.version.enforce === 1){
												that.$store.commit("changeUpLoad",res.data.version.enforce)
											}else{
												that.$store.commit("changeUpLoad",2)
											}
											
											if(res.data.update === 'apk'){
												res.data.version.package_type = 0
											}else{
												res.data.version.package_type = 1
											}
											goTo({url:'/uni_modules/rt-uni-update/components/rt-uni-update/rt-uni-update?obj='+JSON.stringify(res.data.version)})
										}
									},
									fail(e) {
										console.log(e)
									}
								})
							}
						}
					}
				})
			})
			// #endif
		},
		mounted() {
			if(this.isTabbar){
				uni.hideTabBar()
			}
		},
		methods: {
			downQrCode(){
				this.$emit("clickQrCode",true)
			}
		}
	}
</script>

<style scoped lang="scss">
	.shop-bg-img{
		width: 750upx;
		height: 100vh;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 1;
	}
	.top-bg-color{
		width: 750upx;
		height: 452upx;
		position: absolute;
		top: 0;
		left: 0;
	}
	.public-view{
		width: 750rpx;
		min-height: 100vh;
		display: flex;
		flex-direction: column;
		position: relative;
		background-color: #f8f9fc;
	}
</style>